package spring.jpa.repository.impl;

import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import spring.jpa.entity.Customer;
import spring.jpa.repository.CustomerRepository;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.PersistenceContext;
import javax.persistence.PersistenceUnit;

@Repository
@Transactional(rollbackFor = {Exception.class})
public class CustomerRepositoryImpl implements CustomerRepository {
    @PersistenceUnit
    private EntityManagerFactory emf;

    @PersistenceContext
    // @PersistenceContext(unitName = "jpaname")
    private EntityManager em;

    @Override
    public void save(Customer customer) {
        System.out.println(emf.createEntityManager());
        em.persist(customer);
    }
}